#include "app.h"
#include "data_sqlite.h"
#include <qobject.h>
App::App()
{
	if (m_ins != nullptr)
		throw("App instance is runing already!");
	else {
		m_ins = this;
		//init();
	}
}

App::~App()
{
	qDebug() << "deleting data_sqlite.";

}

void App::init()
{
	qSetMessagePattern("[%{time h:mm:ss.zzz} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] : %{message}");
	m_sqlfile = std::filesystem::current_path().parent_path().parent_path().append("data").append("base.db");
	m_datareader = std::make_unique<DataSqlite>();
	m_datareader->initialize(m_sqlfile.string());
}
DataReader* App::dataReader()
{
	return m_datareader.get();
}

App*  App::m_ins = nullptr;
App* App::instance()
{
	return m_ins;
}
